<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@page import="java.text.DateFormat" %>
<%@page import="java.text.SimpleDateFormat" %>

<%@page import="com.easyattendance.services.AddProxyService"%>
<%@page import="java.util.Date"%>
<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@ page import="com.easyattendance.services.TimeTableService" %>
<%@ page import="com.easyattendance.services.AddTeacherService" %>
<%@ page import="com.easyattendance.services.AddClassService" %>
<%@ page import="com.easyattendance.services.AddAllTimeSlotsService" %>
<%@ page import="com.easyattendance.services.AddSubjectService" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Teacher - Take Attendance</title>

<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" />

<link rel="stylesheet" href="<%=request.getContextPath()%>/views/css/ui/jquery-ui-1.10.4.custom.min.css">
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.core.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.widget.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.accordion.js"></script>
<script>
	/* If want to fix height inner content of accordion - 
		remove 'heightStyle' line (and the above comma too :p ).
	*/
	$(function() {
		$( "#accordion" ).accordion({
			collapsible: true,
			heightStyle: "content",
		});
	});
</script>

</head>

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp" />
<jsp:include page="../common/checkTeacherRole.jsp" />

<% /* Get timeSlots in HashMap */
String currentUser = (String) session.getAttribute("currentUser");
AddTeacherService addTeacherService = new AddTeacherService();
AddClassService addClassService = new AddClassService();

AddSubjectService addSubjectService = new AddSubjectService();

String sectionId = addTeacherService.getSectionEmailIdByTeacherId(currentUser);
/* String class_id = addClassService.getClassIdByTeacherId(currentUser); */
TimeTableService service = new TimeTableService();
AddAllTimeSlotsService addAllTimeSlotsService = new AddAllTimeSlotsService();

String[] daysMap = service.getDaysHeader();

//Map<String, String> timeSlotsMap = new HashMap<String, String>();
String[] timeSlotsMap = addAllTimeSlotsService.listAllTimeSlotsBySection(sectionId);

// Teacher Wise Subjects

String[][] teacherSubjects = {null,null};
teacherSubjects = service.getTeacherWiseSubjects(timeSlotsMap, currentUser);
int subjJLength=daysMap.length;

String[][] teacherTimeSlots = {null,null};
teacherTimeSlots = service.getTeacherWisetimeSlots(timeSlotsMap, currentUser);

%>


<% 
	DateFormat dateFormat=new SimpleDateFormat("YYYY-MM-dd");
	Date date = new Date();
	//String today=dateFormat.format(date);
	String today=dateFormat.format(date);
	
	int j = date.getDay();
	
	// For getting teacher's today's proxy time slots 
	AddProxyService addProxyService=new AddProxyService();
	String[] proxySlotsMap=addProxyService.getTeacherWiseProxySlots(currentUser,today);
	
	Teacher proxy_teacher=addTeacherService.getTeacherByEmailId(currentUser);
	
	//Check whether proxy_lectures are empty or not
	
	boolean proxy_empty = true;
	for (int i=0; i<proxySlotsMap.length; i++) {
	  if (proxySlotsMap[i] != null) {
	    proxy_empty = false;
	    break;
	  }
	}

%>
<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">
				<% if(j != 0){ %>
					<div id="accordion" style="clear:both;">
						<% for(int i=0; i < timeSlotsMap.length-1; i++) {  %>
							<% if (teacherSubjects[j-1][i] != null) { System.out.println(daysMap[j-1]);%>
							       <%if(proxy_empty) { %>
											<h3> <%= timeSlotsMap[i] %></h3>
											 <div> 
												Subject: <%=addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getSubject_name() %><br>
												Class: <%=addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getClassobj().getClass_name() %><br>
												<% if(timeSlotsMap[i].equals("11:20")) { 
													String classsId = addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getClassobj().getClass_id();%>
													<a href="${pageContext.request.contextPath}/AttendanceServlet?classid=<%=classsId%>"> Click Here </a>to take attendance 
										    </div> 
												<% } 
							          }
							       else{ %>
								
									   <% for(int k=0;k<proxySlotsMap.length;k++) { 
										    if(proxySlotsMap[k]!=null) {  %>  
											  <% if(proxySlotsMap[k].equals("11:20")) { %>
													<h3> Proxy Lecture:<%= proxySlotsMap[k] %></h3>
												   <div>  
													  <% String proxy_teacherSubject;
													   proxy_teacherSubject = addProxyService.getSubjectByTimeSlot(proxySlotsMap[k], currentUser); %>
													   Subject: <%=addSubjectService.getSubjectBySubjectId(proxy_teacherSubject).getSubject_name() %><br>
													   Class: <%=addSubjectService.getSubjectBySubjectId(proxy_teacherSubject).getClassobj().getClass_name() %><br>	
																	
													   <% String classsId = addSubjectService.getSubjectBySubjectId(proxy_teacherSubject).getClassobj().getClass_id(); %>
													   <a href="${pageContext.request.contextPath}/AttendanceServlet?classid=<%=classsId%>"> Click Here </a>to take attendance 
												  </div>
													
											 <% }else if(proxySlotsMap[k].compareTo(timeSlotsMap[i])<0){%>
											 		<h3>Proxy Lecture: <%= proxySlotsMap[k] %></h3>
													<div> 
													  <% String proxy_teacherSubject;
													   proxy_teacherSubject = addProxyService.getSubjectByTimeSlot(proxySlotsMap[k], currentUser); %>
													   Subject: <%=addSubjectService.getSubjectBySubjectId(proxy_teacherSubject).getSubject_name() %><br>
													   Class: <%=addSubjectService.getSubjectBySubjectId(proxy_teacherSubject).getClassobj().getClass_name() %><br>	
													</div> 
											 		
											 <% } %>
											 	  <h3> <%= timeSlotsMap[i] %></h3>
											 	  <% if(!timeSlotsMap[i].equals("11:20")) {  %>
												  <div>
													Subject: <%=addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getSubject_name() %><br>
													Class: <%=addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getClassobj().getClass_name() %> <br>
												  </div>
												<% }else if(timeSlotsMap[i].equals("11:20")) { %>
													<div>
													Subject: <%=addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getSubject_name() %><br>
													Class: <%=addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getClassobj().getClass_name() %><br>
													<% String classsId = addSubjectService.getSubjectBySubjectId(teacherSubjects[j-1][i]).getClassobj().getClass_id();%>
													<a href="${pageContext.request.contextPath}/AttendanceServlet?classid=<%=classsId%>"> Click Here </a>to take attendance 
												 </div>	
												  
											  <% } %>
										  <%} %>	 		
									 <%} %>
								  <%}%>													
							 <% }%> 
					    <% } %>
					</div>		 	
				<% }else{  %>
					<h3>Its Sunday today. Take rest.</h3>
				<% } %>
		</div>
  </div>
  
		<!-- Sidebar -->
	     <div id="sidebar">   

			<!-- Sidebar Header - Logo & Name -->
			 <jsp:include page="../common/sidebarHeader.jsp" /> 

			<jsp:include page="teacherMenu.jsp" /> 
			
			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div> 

	</div>	
	<script type="text/javascript">
		$(function(){
			$("#takeAttendance").addClass("current_page_item");
		});
	</script>
	
</body>
</html>